package message.preset;

import java.nio.ByteBuffer;

import message.BasicMessageBuilder;
import message.BasicMessageParser;
import message.EmptyMessageBuilder;
import message.EmptyMessageParser;
import message.ObjectMessageBuilderSupplier;
import message.ObjectMessageParserSupplier;
import message.reflect.HandlerMapper;

public class PresetHandlerMapper extends HandlerMapper {
	
	{
		add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getInt), 
				(obj) -> new BasicMessageParser<Integer>(ByteBuffer::putInt, (int)obj),
				"int", "java.lang.Integer")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getShort), 
				(obj) -> new BasicMessageParser<Short>(ByteBuffer::putShort, (short)obj),
				"short", "java.lang.Short")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getDouble), 
				(obj) -> new BasicMessageParser<Double>(ByteBuffer::putDouble, (double)obj),
				"double", "java.lang.Double")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getFloat), 
				(obj) -> new BasicMessageParser<Float>(ByteBuffer::putFloat, (float)obj),
				"float", "java.lang.Float")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getLong), 
				(obj) -> new BasicMessageParser<Long>(ByteBuffer::putLong, (long)obj),
				"long", "java.lang.Long")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::getChar), 
				(obj) -> new BasicMessageParser<Character>(ByteBuffer::putChar, (char)obj),
				"char", "java.lang.Character")
		.add((callback) -> new BasicMessageBuilder(callback, (b)->b.get()!=0), 
				(obj) -> new BasicMessageParser<Boolean>((b, x)->b.put((byte)(x?1:0)), (boolean)obj),
				"boolean", "java.lang.Boolean")
		.add((callback) -> new BasicMessageBuilder(callback, ByteBuffer::get), 
				(obj) -> new BasicMessageParser<Byte>(ByteBuffer::put, (byte)obj),
				"byte", "java.lang.Byte")
		.add((callback) -> new StringMessageBuilder(callback, this),
				(obj) -> new StringMessageParser(obj, this),
				"java.lang.String")
		.add(new ArrayMessageBuilderSupplier(), new ArrayMessageParserSupplier(),
				"java.util.List", "java.util.ArrayList")
		.add(this.OBJECT_BUILDER_SUPPLIER = new ObjectMessageBuilderSupplier(this), 
				this.OBJECT_PARSER_SUPPLIER = new ObjectMessageParserSupplier(this),
				"java.lang.Object", "nrpc.message.Message")
		.add((callback) -> new EmptyMessageBuilder(callback),
				(obj) -> new EmptyMessageParser(), 
				"void");
	}
	
	public PresetHandlerMapper() {}
	
}
